ArcPadScripting
RecordSet Example 1

Description

MaxByEOF finds the maximum value in the ID field of the first layer by moving forward through the recordset.

VBScript Code

Copy Code
Sub MaxByEOF
  Dim objRS, objLayer, varCurrValue, varMax
  'Get a reference to the first layer
  Set objLayer = Application.Map.Layers(1)
  'Get a reference to the layer's recordset
  Set objRS = objLayer.Records
  'Move to the first record
  objRS.MoveFirst
  'Initialize varMax to the first record
  varMax = objRS.Fields("ID").Value
  'Move forward through all the records, updating varMax if necessary
  While Not objRS.EOF
    varCurrValue = objRS.Fields("ID").Value
    If varCurrValue > varMax Then
      varMax = varCurrValue
    End If
    objRS.MoveNext
  Wend
  Set objRS = Nothing
  Set objLayer = Nothing
  'Display the max in a message box
  MsgBox "The maximum value is: " & CStr(varMax)    
End Sub
 
Sub MaxByBOF
  Dim objRS, objLayer, varCurrValue, varMax
  'Get a reference to the first layer
  Set objLayer = Application.Map.Layers(1)
  'Get a reference to the layer's recordset
  Set objRS = objLayer.Records
  'Move to the last record
  objRS.MoveLast
  'Initialize varMax to the last record
  varMax = objRS.Fields("ID").Value
  'Move backwards through all the records, updating varMax if necessary
  While Not objRS.BOF
    varCurrValue = objRS.Fields("ID").Value
    If varCurrValue > varMax Then
      varMax = varCurrValue
    End If
    objRS.MovePrevious
  Wend
  Set objRS = Nothing
  Set objLayer = Nothing  
  'Display the max in a message box
  MsgBox "The maximum value is: " & CStr(varMax)    
End Sub